module.exports = function ($scope, $modalInstance, FileUploader,$resource, $modal, item, flag, toaster){
  var url = '';
  if(item){
    console.log("1");
    url = '/api/as/mc/shopproduct/updateCardsProduct'
    // $scope.opeinfo = item;
  }else{
    console.log("2");
    url =  '/api/as/mc/shopproduct/insertCardsProduct'
  }
  $scope.opeinfo = {
    'img' : '',
    'product_code':''
  }
  init();
  $scope.searchform = {};
 

  function init(){
      $scope.opeinfo = flag ? {'flag': true} : angular.copy(item);
      console.log($scope.opeinfo);
      $resource('/api/as/mc/shopproduct/findMyProductNoPageList', {}, {}).save({}, function (res) {
    if (res.errcode === 0) {
      $scope.ProductList = res.data;
      $scope.searchform.product_code = $scope.opeinfo.product_code;
      // $scope.opeinfo.product.product_code = $scope.opeinfo.product_code;
      // $scope.opeinfo.product.product_name = $scope.opeinfo.product_name;
    } else {
      toaster.error({ title: '', body: res.errmsg });
    }
  });
  }
  //保存
  $scope.save = function (){
    console.log($scope.searchform);
      $scope.opeinfo.product_code = $scope.searchform.product_code;
      $resource(url, {}, {}).save($scope.opeinfo, function(res){
          if(res.errcode === 0){
              toaster.success({title: '', body: '保存成功'});
              $modalInstance.close();
          }else{
              toaster.error({title: '', body: res.errmsg});
          }
      });
  }
  //取消
  $scope.cancel = function () {
      $modalInstance.dismiss('cancel');
  }
  var uploader = $scope.uploader = new FileUploader({
    url: 'https://txy.juyouhx.com/Api/Api/ObjectToOss?topdir=aa&selfdir=bb'
  });
  
  uploader.filters.push({
    name: 'imageFilter',
    fn: function(item /*{File|FileLikeObject}*/, options) {
        var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
        return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
    }
  });    
  uploader.onSuccessItem = function(fileItem, response, status, headers) {
    console.log( response.savename);
    $scope.opeinfo.img = response.savename; 
  
  };
  
};

